import request from "./request.js";

function uploadImage(options) {
	let defaultOptions = {
		objClassName: "Default"
	}
	const newOptions = Object.assign(defaultOptions, options);
	return new Promise((resolve, reject)=> {
		uni.chooseMedia({
			count: 1,
			mediaType: ['image'],
			sourceType: ['album', 'camera'],
			maxDuration: 30,
			camera: 'back',
			success: (chooseImageRes) => {
				const tempFilePaths = chooseImageRes.tempFiles;
				const path = tempFilePaths[0].tempFilePath;
				request.upload(path, newOptions).then((res)=> {
					resolve(res);
				})
			},
			complete: (e) => {
			}
		})
	});
}

export default {
	uploadImage: uploadImage
}